﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/**
 * Tom the Spider <3
 */
public class Tom : MonoBehaviour {

	public float newPosInterval;

	private List<Renderer> renderers;

	public void Start()
	{
		renderers = new List<Renderer>();
		foreach(Transform child in transform)
		{
			if(child.renderer != null)
				renderers.Add(child.renderer);
		}
	}

	public void MoveAround()
	{
		StartCoroutine (DoMoveAround());
	}

		private IEnumerator DoMoveAround()
	{
		// enable renderers
		foreach(Transform t in transform)
			t.renderer.enabled = true;

		/* x coordinate
			from -27 to 23
			
		   z coordinate
		   from -22 to 26
	   */
		//Random random = new Random();

		while(true)
		{
			int randomX = Random.Range(-27, 23);
			int randomZ = Random.Range(-22, 26);
			Vector3 newPosition = new Vector3(randomX, gameObject.transform.position.y, randomZ);
			gameObject.transform.position = newPosition;
			yield return new WaitForSeconds(newPosInterval);

		}
	}
}
